package com.xsp.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xsp.eduservice.entity.EduCourse;
import com.xsp.eduservice.entity.EduTeacher;
import com.xsp.eduservice.service.EduCourseService;
import com.xsp.eduservice.service.EduTeacherService;
import com.xsp.commonutils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/front/teacher")
public class TeacherFrontController {

    @Autowired
    EduTeacherService teacherService;
    @Autowired
    EduCourseService courseService;

    //另外一种分页(用于前台讲师)
    @GetMapping("{page}/{limit}")
    public R pageTeacherList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> teacherPage = new Page<EduTeacher>(page, limit);
        Map<String,Object> map = teacherService.pageTeacherList(teacherPage);
        return R.ok().data(map);
    }

    //讲师id查询基本信息
    //基本信息:讲师信息,课程信息
    @GetMapping("getInfo/{id}")
    public R getInfoById(@PathVariable String id){
        EduTeacher teacher = teacherService.getById(id);
        List<EduCourse> courseList = courseService.selectByTeacherId(id);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
